<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
      <a-row>
        <a-col :span="24">
          <a-form-model-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="htNumber">
            <a-input v-model="model.htNumber" placeholder="请输入合同编号" style="width: 100%"  disabled/>
          </a-form-model-item>
        </a-col>
        <a-col :span="24">
          <a-form-model-item label="应收款编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="yskNumber">
            <a-input v-model="model.yskNumber" placeholder="请输入应收款编号" style="width: 100%"  disabled/>
          </a-form-model-item>
        </a-col>
        <a-col :span="24">
          <a-form-model-item label="回款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="collectionAmounts">
            <a-input-number v-model="model.collectionAmounts" placeholder="请输入应收金额" style="width: 100%" />
          </a-form-model-item>
        </a-col>
      </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDepCustom'
import moment from 'moment'

export default {
  name: 'productInfoForm',
  components: {
    JSelectUserByDep
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      AboutAmount:0,
      model: {
        htNumber:'',
        yskNumber:'',
        collectionAmounts:0,
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        collectionAmounts: [
          { required: true, message: '请输入回款金额!' },
          {
            validator: (rule, value, callback) => {
              if (Number(value) > this.AboutAmount) {
                callback(new Error(`回款金额不能超过${this.AboutAmount}`))
              }
              else if (Number(value) < 0 || Number(value) == 0 ) {
                callback(new Error(`回款金额必须大于0`))
              }
              else {
                callback()
              }
            },
            trigger: ['blur']
          }
        ],
      },
      url: {
        add: "/payment/paymentCollection/add",
        edit: "/payment/paymentCollection/queryById",
        queryById: "/payment/paymentCollection/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      console.log(record)
      this.AboutAmount=record.collectionAmounts
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      that.confirmLoading = true
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = false
          that.$emit('ok', this.model)
        } else {
          that.confirmLoading = false
        }

      })
    }

  }
}
</script>
<style scoped lang="less">
.w100 {
  width: 100%;
}
</style>